<?php
/*****************************************************************
 * Fusion.Board
 *
 * @author                Denis Wrobel
 * @license               http://www.gnu.org/licenses/gpl-3.0.html
 * @version               0.1
 *
 *****************************************************************/

if( !defined( 'IN_SCRIPT' ) )
{
    die( 'Go Away!' );
}

class Language
{
    public $lang_data = array();
    public $months = array();
    public $lang_info = array();
    public $used_lang = '';
    
    public function __construct()
    {
        global $board, $error;
        
        $this->used_lang = $board['language'];
        
        if( !file_exists( LANGUAGES . $this->used_lang . '/lang.php'  ) )
        {
            $error->scriptError( 'Cant find language `' . $this->used_lang . '` in `' . LANGUAGES . '`' );
        }
        else
        {
            @require_once( LANGUAGES . $this->used_lang . '/lang.php' );
            
            $this->lang_data = $lang;
            $this->lang_info = $info;
            $this->months = $months;
        }
    }
    
    /*
     * Return lang string
     * @param string $key Lang array key
     * @param integer $ucfirst use ucfirst?
     */
    public function string( $key, $ucfirst = 1 )
    {
        return ( $ucfirst == 1 ) ? ucfirst( $this->lang_data[ $key ] ) : $this->lang_data[ $key ];
    }
    
    public function sprintf( $string )
    {
	$arg_list = func_get_args();
	$args_num = count($arg_list);
		
	for( $i = 1; $i < $args_num; $i++ )
	{
	    $string = str_replace( '{' . $i . '}', $arg_list[ $i ], $string );
	}
		
        return $string;
    }
}